package com.sujeet.learning.sort;

public class ParallelSortHCL {
	static int a[] = {0,1,8,112,243,4,65};
	static int b[] = {4,9,8,5,3,100,0,1};
	
	public static void sort(int arr[]) {
		for (int i=0; i<arr.length; i++) {
			for(int j=i+1; j<(arr.length); j++) {
				int tmp;
				if (arr[i] > arr[j]) {
					tmp = arr[i];
					arr[i] = arr[j];
					arr[j] = tmp;
				}
			}
		}
	}
	
	public static int[] combine(int a[], int b[]){
		int[] res = new int [a.length+b.length];
		int i=0;
		while(i < a.length) {
			res[i] = a[i];
			i++;
		}
		int j=0;
		while(j < b.length) {
			res[i] = b[j];
			j++;i++;
		}
		return res;
	}
	
	public static void main(String[] args) {
		Thread t1 = new Thread(new Runnable() {
			public void run() {
				sort(a);
			}
		});
		Thread t2 = new Thread(new Runnable() {
			public void run() {
				sort(b);
			}
		});
		
		t1.start();
		t2.start();
		
		try {
			t1.join();
			t2.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		
		int [] res = combine(a,b);
		for (int i=0; i< res.length; i++) {
			System.out.println(res[i]);
		}			
	}
}
